/*
 * Network.java
 *
 * Created on 9 de noviembre de 2006, 03:59 PM
 */

package cflp;


/**
 *
 * @author tavobula
 */
public class Network {
    
    private int nodesNumber;
    private int arcsNumber;
    private int[] demand;
    private int[][] distances;
    private int[] warehouseCapacity;
    private int[][] costs;
    private int[] fixedCosts;
    private int demTotal;
    
    /** Creates a new instance of Network */
    public Network(String name) {
        ProblemReader pr=new ProblemReader(name);
        this.nodesNumber=pr.getNodesNumber();
        this.arcsNumber=pr.getArcsNumber();
        this.demand=pr.getDemand();
        this.distances=pr.getDistances();
        this.fixedCosts=pr.getFixedCosts();
        this.warehouseCapacity=pr.getWarehouseCapacity();
        this.costs=pr.getCosts();
        this.demTotal=calculateDemTotal();
    }
    
    public int calculateDemTotal(){
        int dTotal=0;
        for(int i=0;i<nodesNumber;i++){
            dTotal=dTotal+demand[i];
        }
        return dTotal;
    }
    
    public void printNetwork(){
        System.out.println("set j/1*"+nodesNumber+"/;");
        System.out.println("alias(i,j);");
        System.out.println("");
        System.out.println("parameter demanda(i)/");
        for(int j=0;j<nodesNumber;++j){
            if(j<=8)System.out.print((j+1)+" \t");
            if(j>8)System.out.print((j+1)+"\t");
            System.out.println("\t"+demand[j]);
        }
        System.out.println("/;");
        System.out.println("parameter capacidad(i)/");
        for(int j=0;j<nodesNumber;++j){
            if(j<=8)System.out.print((j+1)+" \t");
            if(j>8)System.out.print((j+1)+"\t");
            System.out.println("\t"+warehouseCapacity[j]);
        }
        System.out.println("/;");
        System.out.println("parameter costosFijos(i)/");
        for(int i=0;i<nodesNumber;++i){
            if(i<=8)System.out.print((i+1)+" \t");
            if(i>8)System.out.print((i+1)+"\t");
            System.out.println("\t"+fixedCosts[i]);
        }
        System.out.println("/;");
        java.text.DecimalFormat myFormatter = new java.text.DecimalFormat("0000");
        System.out.println("table dist(i,j)");
        System.out.println("          1           2           3           4           5           6           7           8           9           10          11          12          13          14          15          16          17          18          19          20          21          22          23          24          25          26          27          28          29          30          31          32          33          34          35          36          37          38          39          40          41          42          43          44          45          46          47          48          49          50");
        for(int i=0;i<distances.length;++i){
            if(i<=8)System.out.print((i+1)+" \t");
            if(i>8)System.out.print((i+1)+"\t");
            for(int j=0;j<distances[i].length;++j){
                int dist=(distances[i][j]>0)?distances[i][j]:9999;
                System.out.print(myFormatter.format(dist)+"\t");
            }
            System.out.println("");
        }
        System.out.println("");
        System.out.println("table costos(i,j)");
        System.out.println("          1           2           3           4           5           6           7           8           9           10          11          12          13          14          15          16          17          18          19          20          21          22          23          24          25          26          27          28          29          30          31          32          33          34          35          36          37          38          39          40          41          42          43          44          45          46          47          48          49          50");
        for(int i=0;i<costs.length;++i){
            if(i<=8)System.out.print((i+1)+" \t");
            if(i>8)System.out.print((i+1)+"\t");
            for(int j=0;j<costs[i].length;++j){
                int cost=(costs[i][j]>0)?costs[i][j]:9999;
                System.out.print(myFormatter.format(cost)+"\t");
            }
            System.out.println("");
        }
        System.out.println("");
     
    }
    
    public int getNodesNumber() {
        return nodesNumber;
    }
    
    public int[] getDemand() {
        return demand;
    }
    
    public int[][] getDistances() {
        return distances;
    }
    
    public int getCapacity(){
        return warehouseCapacity[0];
    }
        
    public int[] getWarehouseCapacity() {
        return warehouseCapacity;
    }
    
    public int[][] getCosts() {
        return costs;
    }
    
    public int[] getFixedCosts() {
        return fixedCosts;
    }
    
    public int getDemTotal() {
        return demTotal;
    }

    public int getArcsNumber() {
        return arcsNumber;
    }
    
}
